package com.zqh.springframework;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by xsls
 */
@AllArgsConstructor
public class JdkDynimcProxy implements InvocationHandler {

	private Object target;



	public <T> T getProxy() {
		return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),
				target.getClass().getInterfaces(),
				this
		);
	}

	//  Service.add();   //创建动态代理
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

		System.out.println("创建动态代理成功。。。。");
		return method.invoke(target,args);
		// 后置
	}
}
